package com.JackTang.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

/**
 * @author Jack Tang
 * @description
 * @create 2023-05-10 21:14
 */
@WebServlet(urlPatterns = {"/demo01"},initParams = {
        @WebInitParam(name = "hello",value = "world"),
        @WebInitParam(name = "uname",value = "ok")
})
public class Demo01Servlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        ServletConfig config = getServletConfig();
        String initValue = config.getInitParameter("hello");
        System.out.println("initValue = " + initValue);

        ServletContext servletContext = getServletContext();
        String contextConfigLocation = servletContext.getInitParameter("contextConfigLocation");
        System.out.println("contextConfigLocation = " + contextConfigLocation);
    }
}

// Servlet生命周期：实例化、初始化、服务、销毁
